package com.lineage.data.item_etcitem.add;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1MonsterInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Teleport;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.world.WorldMob;
import java.util.Iterator;

public class Boss_TrackingTechnique extends ItemExecutor {
  public static ItemExecutor get() {
    return new Boss_TrackingTechnique();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    pc.sendPackets((ServerBasePacket)new S_SystemMessage("正在找寻目标中......"));
    L1MonsterInstance find_npc = null;
    Iterator<L1MonsterInstance> itr = WorldMob.get().getAllMonster().iterator();
    while (itr.hasNext()) {
      L1MonsterInstance boss = itr.next();
      if (boss.getMapId() == pc.getMapId() && !boss.isDead() && boss.getNpcTemplate().is_boss())
        find_npc = boss; 
      if (find_npc != null)
        break; 
    } 
    if (find_npc != null) {
      L1Teleport.teleport(pc, find_npc.getX(), find_npc.getY(), find_npc.getMapId(), pc.getHeading(), true);
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("传送至Boss：" + find_npc.getName() + " 的身边..."));
    } else {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("这张地图已经没有Boss的踪迹..."));
    } 
    pc.getInventory().removeItem(item, 1L);
  }
}
